# import pyvista as pv
#
# pv.global_theme.allow_empty_mesh = True
#
# # 读取 VTU 文件
# filename = './2024-11-06/22-36-43/visual/result_u_v_t-15.vtu'
# dataset = pv.read(filename)
#
# print(dataset)
#
# # 创建一个平面切片
# slice_plane = dataset.slice(normal=[0, 0, 1])  # 沿 y 轴切片
#
# print(slice_plane)
#
# # 创建一个渲染窗口
# plotter = pv.Plotter()
#
# # 添加切片数据到渲染窗口
# plotter.add_mesh(slice_plane, color='black')
#
# # 显示渲染窗口
# plotter.show()
import vtkmodules.all as vtk
filename = "./2024-11-06/22-36-43/visual/result_u_v_t-15.vtu"

reader = vtk.vtkXMLUnstructuredGridReader()
reader.SetFileName(filename)
reader.Update()


reader.GetOutput().GetPointData().SetActiveVectors('Vectors')


renderer = vtk.vtkRenderer()
render_window = vtk.vtkRenderWindow()
render_window.AddRenderer(renderer)

ColorTransferFunction = vtk.vtkColorTransferFunction()
ColorTransferFunction.AddRGBPoint(0, 1, 1, 1)

mapper = vtk.vtkDataSetMapper()
mapper.SetInputData(reader.GetOutput())
mapper.SetInputConnection(reader.GetOutputPort())
mapper.SetLookupTable(ColorTransferFunction)
# mapper.SetScalarRange(data.GetScalarRange())


actor = vtk.vtkActor()
actor.SetMapper(mapper)
actor.GetProperty().SetInterpolationToFlat()
actor.GetProperty().SetColor(1, 1, 1)
actor.GetProperty().SetSpecularPower(20)

renderer.AddActor(actor)

render_window.SetSize(800, 800)
render_window.Render()

iren = vtk.vtkRenderWindowInteractor()
iren.SetRenderWindow(render_window)
iren.Initialize()
iren.Start()